package config

import (
	"api/public/global"
	"gitee.com/dreamwood/ez"
)

type LoggerConfig struct {
	LogLevel string `yaml:"log-level"`
	LogTo    string `yaml:"log-to"`
	FilePath string `yaml:"file"`
}

var ezLogger *ez.Logger

func InitLogger() {
	ez.Debug("MYSQL 开始初始化")
	lc := new(LoggerConfig)
	ez.CreateConfigFromYml("./app.yaml", "logger", &lc)

	ezLogger = ez.CreateLogger()
	switch lc.LogTo {
	case "Nsq":
		ezLogger.NsqPubAddr = GetCore().NsqPubAddr
		ezLogger.InitMqLogger()
		ezLogger.UseMqLogger()
		//lg := ezLogger.GetMqLogger()
		//lg.TopicName = GetService().App.Id

	case "Console":
		ezLogger.InitConsoleLogger()
		ezLogger.UseConsoleLogger()
		//lg := ezLogger.GetConsoleLogger()
		//lg.Prefix = GetService().App.Id

	case "File":
		ezLogger.FilePath = lc.FilePath
		ezLogger.InitFileLogger()
		ezLogger.UseFileLogger()
		//lg := ezLogger.GetFileLogger()
		//lg.Prefix = GetService().App.Id
	default:
		ezLogger.UseNoLogger()
	}

}

func GetLogger() *ez.Logger {
	if ezLogger == nil {
		InitLogger()
	}
	global.LOG = ezLogger
	return ezLogger
}
